package module.edittroop.model
{
	
	import com.darwin.darwinIsometric.core.isoConst.IsoType;
	import com.darwin.darwinMVC.core.CmdNameList;
	import com.darwin.darwinMVC.mvc.Command;
	
	import main.AppControllerList;
	import main.mvc.GModelData;
	
	import module.edittroop.cmds.EditTroopCmdConst;
	import module.edittroop.model.dataObj.ArmsConfigObj;
	import module.edittroop.model.dataObj.HeroConfigObj;
	import module.edittroop.model.dataObj.TroopInfoObj;
	import module.scene.consts.SceneConst;
	import module.scene.model.dataObj.TroopIsoDataObj;

	/**
	 *编组部队数据层 
	 * @author jichang
	 * 
	 */
	public class EditTroopModelData extends GModelData
	{
		public function EditTroopModelData()
		{
			var $cmd_1:CmdNameList = new CmdNameList(EditTroopCmdConst.GET_GROUP_INFO);
			register($cmd_1,userInfo);
			var $cmd_2:CmdNameList = new CmdNameList(EditTroopCmdConst.RT_DISSLOVE_TROOP);
			register($cmd_2,dissloveTroop);
			var $cmd_3:CmdNameList = new CmdNameList(EditTroopCmdConst.RT_EDIT_TROOP_METHO);
			register($cmd_3,editNew);
		}
	/**
	 *处理后台发过来的新队伍基本信息 
	 * @param data
	 * 
	 */		
		private function editNew(data:Object):void
		{
			var newObj:Object = new Object;
			newObj = data["troop_gen"]["data"];
			var obj:TroopIsoDataObj = new TroopIsoDataObj();
			obj.parseDynamicData(newObj);
			obj.direction = 180;
			var $cmd:Command = new Command(EditTroopCmdConst.EDIT_NEW_TROOP_SUCCESS);
			$cmd.data = obj;
			dispatch($cmd);
		}
		/**
		 *处理删除队伍 
		 * 
		 */		
		private function dissloveTroop(data:Object):void
		{
			if(data && data.hasOwnProperty("troop_dissolve"))
			{
				var $cmd:Command = new Command(EditTroopCmdConst.DELETE_TROOP_FROM_MODEL);
				$cmd.data = {"troopId":data["troop_dissolve"]["troop_id"]};
				dispatch($cmd);
			}
		}
		private function userInfo(data:Object):void
		{
			var array:Array = new Array();
			var cmd:Command = new Command(EditTroopCmdConst.EDIT_TROOP_GROUP_INFO,this);
			for (var i:Object in data["group_info"])
			{
				var obj:TroopInfoObj = new TroopInfoObj();
				obj = TroopInfoObj.phaseData(data["group_info"][i]);
				array.push(obj);
			}
			cmd.data = array;
			dispatch(cmd);
		}
		public function get heroConfigArr():Array
		{
			return this.getDataBySource("hero") as Array;
		}
		public function get armsConfigArr():Array
		{
			return this.getDataBySource("arms") as Array;
		}
		public function get skillConfigArr():Array
		{
			return this.getDataBySource("skill") as Array;
		}
		/*===============测试=====================*/
		public function disslove():void
		{
			/*var $cmd:Command = new Command(EditTroopCmdConst.DELETE_TROOP_FROM_MODEL);
			$cmd.data.playerID = 13216541;
			dispatch($cmd);*/
		}
	}
}